#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
using std::cout;
using std::cin;
using std::endl;


class Stack
{
public:
	Stack(int capacity = 4)
	{

		_arr = (int*)malloc(sizeof(int) * capacity);
		if (_arr == nullptr)
		{
			perror("malloc fail");
			return;
		}
		_size = 0;
		_capacity = capacity;
	}

	void Push(int x)
	{
		if (_capacity == _size)
		{
			int newcapacity = _capacity == 0 ? 4 : _capacity * 2;
			int* newarr = (int*)realloc(_arr, sizeof(int) * newcapacity);
			if (newarr == nullptr)
			{
				perror("arr realloc fail");
				exit(1);
			}
		}
		_arr[_size++] = x;
	}

	int Top()
	{
		return _arr[_size - 1];
	}

	Stack(const Stack& s)
	{
		cout << "Stack(const Stack& s)" << endl;

		_arr = (int*)malloc(sizeof(int) * s._capacity);
		if (_arr == nullptr)
		{
			perror("malloc fail");
			return;
		}
		memcpy(_arr, s._arr, sizeof(int) * s._size);
		_size = s._size;
		_capacity = s._capacity;
	}

	~Stack()
	{
		cout << "~Stack()" << endl;

		if (_arr)
			free(_arr);
		_size = 0;
		_capacity = 0;
	}
private:
	int* _arr;
	int _size;
	int _capacity;
};


class Date
{
public:

	Date(int year = 2024, int month = 8, int day = 31)
	{
		_year = year;
		_month = month;
		_day = day;
	}

	Date(Date& d)
	{
		_year = d._year;
		_month = d._month;
		_day = d._day;
	}

	~Date()
	{
		cout << "~Date()" << endl;
	}
	void print()
	{
		cout << _year << "/" << _month << "/" << _day << endl;
	}
private:
	int _year;
	int _month;
	int _day;
};

Stack Func()
{
	 Stack st1;
	st1.Push(1);
	st1.Push(2);
	st1.Push(3);


	return st1;
}

int main()
{
	//Date d1;
	//Date d2 = d1;

	Stack st2 = Func();
	cout << st2.Top() << endl;

	return 0;
}